package com.hyou.springboot2.service.base.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.hyou.springboot.base.BaseService;
import com.hyou.springboot2.dao.SysAccountDao;
import com.hyou.springboot2.dto.pojo.SysAccountDO;
import com.hyou.springboot2.service.base.itfc.SysAccountService;

/**
 * SysAccountServiceImpl Service接口实现类
 *
 * @author FengChangshuo
 * @version 1.0.0 2018-11-01 11:27:16 初始创建
 */
public class SysAccountServiceImpl extends BaseService implements SysAccountService {
    
    @Override
    public Long insert(SysAccountDO paramBean) {
        Long newId = getNextId();
        paramBean.setId(newId);
        getMapper(SysAccountDao.class).insert(paramBean);
        return newId;
    }
    
    @Override
    public void insertBatch(List<SysAccountDO> paramBeans) {
        for (SysAccountDO item : paramBeans) {
            Long newId = getNextId();
            item.setId(newId);
        }
        
        getMapper(SysAccountDao.class).insertBatch(paramBeans);
    }
    
    @Override
    public void deleteByPrimaryKey(Long id) {
        getMapper(SysAccountDao.class).deleteByPrimaryKey(id);
    }
    
    @Override
    public void deleteBatchByPrimaryKeys(String ids) {
        String[] idArray = StringUtils.split(ids, ',');
        List<Long> idLst = new ArrayList<>();
        for (String item : idArray) {
            idLst.add(Long.valueOf(item));
        }
        
        deleteBatchByPrimaryKeys(idLst);
    }
    
    @Override
    public void deleteBatchByPrimaryKeys(List<Long> ids) {
        getMapper(SysAccountDao.class).deleteBatchByPrimaryKeys(ids);
    }
    
    @Override
    public void updateByPrimaryKeySelective(SysAccountDO paramBean) {
        getMapper(SysAccountDao.class).updateByPrimaryKeySelective(paramBean);
    }
    
    @Override
    public SysAccountDO getByPrimaryKey(Long id) {
        return getMapper(SysAccountDao.class).selectByPrimaryKey(id);
    }
    
    @Override
    public SysAccountDO getByAccountAndPassword(SysAccountDO paramBean) {
        return getMapper(SysAccountDao.class).selectByAccountAndPassword(paramBean);
    }
    
    @Override
    public List<SysAccountDO> listByConditions(SysAccountDO paramBean) {
        return getMapper(SysAccountDao.class).selectByConditions(paramBean);
    }
    
    @Override
    public PageInfo<SysAccountDO> listByPage(SysAccountDO paramBean, final int pageNum, final int pageSize) {
        PageMethod.startPage(pageNum, pageSize);
        List<SysAccountDO> lst = getMapper(SysAccountDao.class).selectByConditions(paramBean);
        return new PageInfo<>(lst);
    }
    
}
